package com.lingyue.entity.page;


import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

/**
 * @version 1.0.0
 * @author: lzy
 * @date: 2019/12/12 17:25
 */
public class SpringDataPageUtils {

    public static Pageable of(PageParam pageParam) {
        return PageRequest.of(pageParam.getCurrent() - 1, pageParam.getSize());
    }

    public static PageResult to(Page page) {
        return new PageResult(page.getNumber() + 1,
                page.getTotalElements(),
                page.getSize(),
                page.getNumberOfElements(),
                page.getTotalPages(),
                page.isFirst(),
                page.isLast(),
                page.getContent());
    }

}
